package com.shop.www.ssm.trans;


import com.shop.www.JDBCUtils.JDBCUtilsByDruid;

import java.sql.Connection;
import java.sql.SQLException;

public class TransactionManager {

    //开启事务
    public static void beginTrans() throws SQLException {
        Connection connection = JDBCUtilsByDruid.getConnection();
        connection.setAutoCommit(false);
    }

    //提交事务
    public static void commit() throws SQLException {
        Connection connection = JDBCUtilsByDruid.getConnection();
        connection.commit();
        JDBCUtilsByDruid.close();
    }

    //回滚事务
    public static void rollback() throws SQLException {
        Connection connection = JDBCUtilsByDruid.getConnection();
        connection.rollback();
        JDBCUtilsByDruid.close();
    }
}